home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / jaz_clib.arc / JZPOP.C < prev    next >
Text File  |  1989-04-09  |  1KB  |  47 lines

  1. #include <jaz.h>
  2.  
  3. /*
  4. ┌────────────────────────────────────────────────────────────────────────────┐
  5. │jzpop                                         │
  6. │Pop data off the stack into a data structure                     │
  7. │If fsize <> 0 then we use fsize, otherwise we use the size of the stack data│
  8. │Synopsis                                     │
  9. │   jzpush (&whead,&wdata,10);                             │
  10. │   jzpop  (&whead,wstr,0);                             │
  11. └────────────────────────────────────────────────────────────────────────────┘
  12. */
  13.  
  14. jzpop(fhead,fdata,fsize)
  15. TSTKHEAD *fhead;
  16. char *fdata;
  17. int fsize;
  18. {
  19.   TSTACK *wtemp;
  20.  
  21.   if (fhead->numitems) {    /* don't pop anything if there is no stack */
  22.  
  23.     /** AT this point, wint contains the
  24.      ** size of the data on the stack.
  25.      ** if fsize, use that for number of bytes,
  26.      ** otherwise use the saved size of the data
  27.      **/
  28.  
  29.    if (! fsize)             /* Check user size arg */
  30.      fsize = fhead->last->wint;
  31.  
  32.     memcpy(fdata,fhead->last->pointer,fsize);
  33.  
  34.     wtemp = fhead->last;        /* save temp copy of pointer */
  35.  
  36.     fhead->last = fhead->last->prev;
  37.     fhead->numitems --;         /* decrement count of items */
  38.  
  39.     free(wtemp->pointer);        /* free memory for path */
  40.     free((char *) wtemp);
  41.  
  42.     if (! fhead->last)            /* empty list ? */
  43.       fhead->first = 0;         /* set first = NULL */
  44.  
  45.   }
  46. }
  47.